package com.lycx.businessmanager.controller.contractManager;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.lycx.businessmanager.controller.BaseController;
import com.lycx.businessmanager.model.Contract;
import com.lycx.businessmanager.service.IContractService;

/**
 * controller
 * 
 * @author lambert
 * 
 */

@Controller
@RequestMapping("/contract")
public class ContractController extends BaseController{
	@SuppressWarnings("unused")
	private static Logger log = Logger.getLogger(ContractController.class);
	private IContractService ContractService;

	public void setContractService(IContractService ContractService) {
		this.ContractService = ContractService;
	}

	@RequestMapping(value = "/list")
	public ModelAndView list(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("/contract/list");
		return mv;
	}
	
	@RequestMapping(value = "/getListForPage")
	@ResponseBody
	public List<Contract> getListForPage(Contract Contract,int startNum,int limit){
		List<Contract> ContractList = null;
		try{
		    ContractList = ContractService.selectForPage(Contract,startNum,limit);
		}catch(Exception e){
			e.printStackTrace();
		}
        return ContractList;
	}
	
	@RequestMapping(value = "/getTotalCount",method = RequestMethod.POST)
	@ResponseBody
	public int getTotalCount(Contract Contract){
		return ContractService.selectTotalCount(Contract);
	}
	
	@RequestMapping(value = "/add",method = RequestMethod.POST)
	@ResponseBody
	public String add(Contract Contract){
		String result = null;
		if(Contract!=null){
	        result = ContractService.add(Contract);
		}
        return result;
	}
	
	@RequestMapping(value = "/del",method = RequestMethod.POST)
	@ResponseBody
	public String del(HttpServletRequest request, HttpServletResponse response,int ids[]){
		String result = null;
		result = ContractService.del(ids);
		return result;
	}
	
	@RequestMapping(value = "/mod",method = RequestMethod.POST)
	@ResponseBody
	public String mod(HttpServletRequest request, HttpServletResponse response,Contract Contract){
		String result = null;
		if(Contract!=null){
			result = ContractService.mod(Contract);
		}
		return result;
	}

}
